package study.lagou.com.sqlSession;

import org.dom4j.DocumentException;
import study.lagou.com.config.XMLConfigBuilder;
import study.lagou.com.pojo.Configuration;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @Description: 功能描述
 * @Author houjh
 * @Email: happyxiaohou@gmail.com
 * @Date: 2021-1-28 22:49
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        //1、解析配置文件，将配置文件封装到Configuration对象当中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        //2、创建sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new DefaultSessionFactory(configuration);
        return sqlSessionFactory;
    }
}

